﻿using AbpApplication.AppServices;
using AbpApplication.InPut;
using Azure;
using Flurl.Http;
using HandyControl.Controls;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Newtonsoft.Json;
using NewWms.Apiservice.Dto;
using NewWms.Extend;
using Reconstruct_Desktop.Apiservice.Dto;
using Reconstruct_Desktop.Apiservice.InPut;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using wms_wpf;
using wms_wpf.Apiservice;
using wms_wpf.Extend;
using wms_wpf.InPut;

namespace NewWms.Apiservice
{
    public class BaseService_Client : IBaseService_Client
    {
        string config = GlobalVariable.Config;
 

        public async Task<bool> Create_Inlethouse(InPut_BaseService9_Client input)
        {
            var url = $"http://{config}/api/BaseService/Create_Inlethouse";
            var data = input;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return Response.State;
            }
            else
            {
               Growl.Info(Response.Msg);
                return Response.State;
            }
        }//配置入库口
        public async Task<bool> Create_Inlethouses(InPut_BaseService9_Client input)
        {
            var url = $"http://{config}/api/BaseService/Create_Inlethouses";
            var data = input;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");           
                return Response.State;
            }
            else
            {
                Growl.Info(Response.Msg);
                return Response.State;
            }
        }//配置缓存口
        public async Task<bool> CreateMaterialBase(InPut_BaseService7_Client inPut)//物料入库
        {

            
            var url = $"http://{config}/api/BaseService/CreateMaterialBase"; 
            var data = inPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                MessageBox.Show(Response.Msg);
                return false;
            }
        }
        public async Task<bool> Create_Boxs(InPut_BaseService_Client input)
        {
            try
            {
                var url = $"http://{config}/api/BaseService/Create_Boxs";
                var data = input;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {
                    Growl.Success(Response.Msg, "msg");
                    return Response.State;
                }
                else
                {
                    Growl.Info(Response.Msg);
                    return Response.State;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("Create_Boxs", ex);
                return false;
            }

        }//加盒子
        public async Task<bool> Create_Warehouses(InPut_BaseService3_Client input)//配库位
        {
            try
            {
                var url = $"http://{config}/api/BaseService/Create_Warehouses";
                var data = input;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {
                    Growl.Success(Response.Msg, "msg");
                    return Response.State;
                }
                else
                {
                    Growl.Info(Response.Msg);
                    return Response.State;
                }
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("Create_Warehouses", ex);
                return false;
            }
        }
        public async Task<bool> DeleteBox(InPut_BaseService8_Client InPut)
        {
            try
            {
                var url = $"http://{config}/api/BaseService/DeleteBox";
                var data = InPut;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {
                    Growl.Success(Response.Msg, "msg");
                    return Response.State;
                }
                else
                {
                    Growl.Info(Response.Msg);
                    return Response.State;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("DeleteBox", ex);
                return false;
            }
        }//删盒子
        public async Task<Tuple<bool,string>> CreateTaskOrder(InPut_BaseService6_Client InPut)//添加agv入库任务
        {
            try
            {
                var url = $"http://{config}/api/BaseService/CreateTaskOrder";
                var data = InPut;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {
                    Growl.Success(Response.Msg, "msg");
                    return Tuple.Create(Response.State, Response.Msg);
                }
                else
                {
                    Growl.Info(Response.Msg);
                    return Tuple.Create(Response.State, "");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("CreateTaskOrder", ex);
                return Tuple.Create<bool,string>(false, "");
            }
        }
        public async Task<bool> DeleteTaskOrder(List<string> InPut)//删除agv任务
        {
            try
            {
                var url = $"http://{config}/api/BaseService/DeleteTaskOrder";
                var data = InPut;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {
                    Growl.Success(Response.Msg, "msg");
                    return Response.State;
                }
                else
                {
                    Growl.Info(Response.Msg);
                    return Response.State;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("DeleteTaskOrder", ex);
                return false;
            }
        }
        public async Task<bool> RemovesMaterial(List<string> InPut)//删料
        {
            try
            {
                var url = $"http://{config}/api/BaseService/RemovesMaterial";
                var data = InPut;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {
                    Growl.Success(Response.Msg, "msg");
                    return Response.State;
                }
                else
                {
                    Growl.Info(Response.Msg);
                    return Response.State;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("RemovesMaterial", ex);
                return false;
            }
        }
        public async Task<Tuple<bool, string,string>> DeleteMaterial(InPut_BaseService4_Client InPut)//取料确认
        {
            try
            {
                var url = $"http://{config}/api/BaseService/DeleteMaterial";
                var data = InPut;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
              
                if (Response.State)
                {
                    View_NeetOutMaterialDto View_NeetOutMaterialDto = JsonConvert.DeserializeObject<View_NeetOutMaterialDto>(Response.Dto.ToString());
                    BarTenderPrint.Label(View_NeetOutMaterialDto.MaterialCode,
                                                     View_NeetOutMaterialDto.MaterialName, View_NeetOutMaterialDto.Batch,
                                                     View_NeetOutMaterialDto.NeetQuantity.ToString(), View_NeetOutMaterialDto.Unit,
                                                     View_NeetOutMaterialDto.OrderNo, View_NeetOutMaterialDto.Consumer_MaterialId,View_NeetOutMaterialDto.printOrder);
                    if (Response.Msg.Contains("这批订单"))
                    {
                        MessageBox.Show(Response.Msg);
                    }
                    else
                    {
                        Growl.Success(Response.Msg, "msg");
                    }
                      
             



                    return Tuple.Create( Response.State, View_NeetOutMaterialDto.BoxPositionCode,View_NeetOutMaterialDto.OrderNo);
                }
                else
                {
                    Growl.Info(Response.Msg);
                    return Tuple.Create<bool, string,string>(false,null,null);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("DeleteMaterial", ex);
                return Tuple.Create<bool, string,string>(false, null,null);
            }
        }
        public async Task<string> UpdateTaskOrderState(InPut_BaseService11_Client InPut)//更新任务状态
        {
            try
            {
                var url = $"http://{config}/api/BaseService/UpdateTaskOrderState";
                var data = InPut;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {
                    
                    return Response.Msg;
                }
                else
                {
                    Growl.Info(Response.Msg, "msg");
                    return Response.Msg;
                }

            }
            catch (Exception ex)
            {
                Growl.Error("接口调用失败", "msg");
                LognetHelper.WriteLog("任务状态修改错误:UpdateTaskOrderState", ex);
                return null;
            }
        }
        public async Task<string> CreateLog(string Type, string Note)//生成日志
        {

            try
            {


                InPut_BaseService15_Client InPut = new InPut_BaseService15_Client();
                InPut.Type = Type;
                InPut.Note = Note;
                InPut.User = Jwt.UserName;
                var url = $"http://{config}/api/BaseService/CreateLog";
                var data = InPut;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {

                    return Response.Msg;
                }
                else
                {
                    return Response.Msg;
                }
            }
            catch (Exception ex)
            {
               
                LognetHelper.WriteLog("CreateLog", ex);
                return null;
            }
        }
        public async Task<Tuple<bool, List<TaskOrderDto>>> CreateTaskOrderOut(InPut_BaseService13_Client InPut)//添加agv出库任务
        {
            try
            {
                var url = $"http://{config}/api/BaseService/CreateTaskOrderOut";
                var data = InPut;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {
                    Growl.Success(Response.Msg, "msg");

                    return Tuple.Create<bool, List<TaskOrderDto>>(true, null);
                }
                else
                {
                    Growl.Info(Response.Msg);
                    return Tuple.Create <bool,List<TaskOrderDto>>(false, null);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("CreateTaskOrderOut", ex);
                return Tuple.Create<bool, List<TaskOrderDto>>(false, null);
            }
        }
        public async Task<Tuple<bool, List<TaskOrderDto>>> CreateNeetOutMaterial(InPut_BaseService10_Client InPut)//手动出库-添加需出料-添加agv任务
        {
            try
            {
                var url = $"http://{config}/api/BaseService/CreateNeetOutMaterial";
                var data = InPut;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {
                    Growl.Success(Response.Msg, "msg");
                    List<TaskOrderDto> Dto = JsonConvert.DeserializeObject<List<TaskOrderDto>>(Response.Dto.ToString());

                    return Tuple.Create(Response.State, Dto);
                }
                else
                {
                    Growl.Info(Response.Msg);
                    return Tuple.Create<bool, List<TaskOrderDto>>(false, null);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("CreateNeetOutMaterial", ex);
                return Tuple.Create<bool, List<TaskOrderDto>>(false, null);
            }
        }
        public async Task<bool> Update_Box(InPut_BaseService2_Client input)//更新箱盒
        {
            try
            {
                var url = $"http://{config}/api/BaseService/Update_Box";
                var data = input;
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {
                    Growl.Success(Response.Msg, "msg");
                    return Response.State;
                }
                else
                {
                    Growl.Info(Response.Msg);
                    return Response.State;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("更新箱盒接口失败:Update_Box", ex);
                return false;
            }
        }
        public async Task<bool> UpdateMaterialBaserQuantity(InPut_BaseService7_Client inPut)
        {
            var url = $"http://{config}/api/BaseService/UpdateMaterialBaserQuantity";
            var data = inPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");

         
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> CreateMaterialProperty(InPut_BaseService14_Client InPut)//添加基础物料
        {
            var url = $"http://{config}/api/BaseService/CreateMaterialProperty";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");


                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> Create_Bintype(InPut_BaseService16_Client InPut)//配置bin
        {
            var url = $"http://{config}/api/BaseService/Create_Bintype";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");


                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<List<BoxTypeDto>> Getlist_Bintypes()//获取bins
        {
            var url = $"http://{config}/api/BaseService/Getlist_Bintypes";
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                List<BoxTypeDto> dtos = JsonConvert.DeserializeObject<List<BoxTypeDto>>(Response.Dto.ToString());
                return dtos;
         
            }
            else
            {
                Growl.Info(Response.Msg);
                return null;
            }
        }
        public async Task<bool> UpdateState_ByWarehouselineId(InPut_BaseService17_Client InPut)//更新状态
        {
            var url = $"http://{config}/api/BaseService/UpdateState_ByWarehouselineId";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> UpdateState_ByInlethouselineId(InPut_BaseService18_Client InPut)//更新入口状态
        {
            var url = $"http://{config}/api/BaseService/UpdateState_ByInlethouselineId";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> UpdateNeetQuantity(InPut_BaseService19_Client InPut)//修改需求数量
        {
            var url = $"http://{config}/api/BaseService/UpdateNeetQuantity";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async  Task<bool> AllocationOrder(InPut_BaseService20_Client InPut)//分配工单出库
        {
            var url = $"http://{config}/api/BaseService/AllocationOrder";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> Deallocate(string Symbol)//解除分配
        {
            var url = $"http://{config}/api/BaseService/Deallocate?Symbol={Symbol}";
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> AllocationOrderAgvTask(InPut_BaseService21_Client InPut)//分配工单出库agv
        {
            var url = $"http://{config}/api/BaseService/AllocationOrderAgvTask";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> Update_SowingWall(string SowingWallLine_Name)//更新播种墙
        {
            var url = $"http://{config}/api/BaseService/Update_SowingWall?SowingWallLine_Name={SowingWallLine_Name}";
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> Polling_OutBound()
        {
            var url = $"http://{config}/api/BaseService/Polling_OutBound";
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> moveContainer_wms(string soltcode, string direction, string TaskType, string BoxCode)//输送线流动
        {

            Ess_InPut5_Client InPut=new Ess_InPut5_Client();
            InPut.TaskType = TaskType;
            InPut.BoxCode = BoxCode;
            InPut.SlotCode = soltcode;
            InPut.Direction = direction;
            InPut.IsEss = false;
            var url = $"http://{config}/api/BaseService/moveContainer_wms";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> DeleteMoveContainer(string boxCode)
        {
            var url = $"http://{config}/api/BaseService/DeleteMoveContainer?boxCode={boxCode}";
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }//删除输送线任务
        public async Task<bool> SendCustomerOutRep(string Consumer_MaterialId)//出库通知
        {
           
                var url = $"http://{config}/api/BaseService/SendCustomerOutRep?Consumer_MaterialId={Consumer_MaterialId}";
                string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
                ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
                if (Response.State)
                {
                    Growl.Success(Response.Msg, "msg");
                    return true;
                }
                else
                {
                    Growl.Info(Response.Msg);
                    return false;
                }
         
    
        }
        public async Task<bool> Manual_FinishOrder(Guid PutOutOrder_id)//手动完成工单
        {
            var url = $"http://{config}/api/BaseService/Manual_FinishOrder?PutOutOrder_id={PutOutOrder_id}";
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> UpdatManualQuantity(InPut_BaseService24_Client InPut)//修改手动出库数量
        {
            var url = $"http://{config}/api/BaseService/UpdatManualQuantity";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> UpdateMaterialQuantity(InPut_BaseService25_Client InPut)//修改数量
        {
            var url = $"http://{config}/api/BaseService/UpdateMaterialQuantity";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> CheckBoxMaterial(string BoxPosition)//查看箱内物料
        {
            var url = $"http://{config}/api/BaseService/CheckBoxMaterial?BoxPosition={BoxPosition}";
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                MessageBox.Show(Response.Msg);
                return true;
            }
            else
            {
           
                return false;
            }
        }
        public async Task<bool> Start_StockTaking(InPut_BaseService26_Client InPut)
        {
            var url = $"http://{config}/api/BaseService/Start_StockTaking";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<Tuple<bool, string>> GetOrderNo(string BoxCode)//根据料号获取工单号
        {
            var url = $"http://{config}/api/BaseService/GetOrderNo?BoxCode={BoxCode}";
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);       
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return Tuple.Create(Response.State, Response.Dto. ToString());
            }
            else
            {
                Growl.Info(Response.Msg);
                return Tuple.Create(Response.State, "");
            }
        }
        public async Task<bool> TaskStatusChange(InPut_EssService InPut)//手动任务状态上报
        {
            var url = $"http://{config}/api/EssService/TaskStatusChange";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponseEss Response = JsonConvert.DeserializeObject<ApiResponseEss>(result);
            if (Response.code==0)
            {
                Growl.Success("恢复成功", "msg");
                return true;
            }
            else
            {
                Growl.Info("恢复失败");
                return false;
            }
        }
        public async Task<bool> SingleOutbount(Guid guid)//单次分配
        {
            var url = $"http://{config}/api/BaseService/SingleOutbount?guid={guid}";
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<bool> UpdateBoxMaterial(InPut_BaseService7_Client inPut)//更换料盒
        {
            var url = $"http://{config}/api/BaseService/UpdateBoxMaterial";
            var data = inPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                MessageBox.Show(Response.Msg);
                return false;
            }
        }
        public async Task<bool> MaterialCheck(InPut_CunsumerService5 InPut)
        {
            var url = $"http://{config}/api/ConsumerService/MaterialCheck";
            var data = InPut;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                MessageBox.Show(Response.Msg);
                return false;
            }
        }
        public async Task<bool> DeleteCustomCheckList( List<Guid> guid)
        {
            var url = $"http://{config}/api/BaseService/DeleteCustomCheckList";
            var data = guid;
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostJsonAsync(data).ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
                Growl.Success(Response.Msg, "msg");
                return true;
            }
            else
            {
                Growl.Info(Response.Msg);
                return false;
            }
        }
        public async Task<string> GetConveyorline()//获取输送线料盒
        {
            var url = $"http://{config}/api/BaseService/GetConveyorline";
            string result = await url.WithHeader("Authorization", " Bearer" + " " + Jwt.JwtKey).PostAsync().ReceiveString();
            ApiResponse Response = JsonConvert.DeserializeObject<ApiResponse>(result);
            if (Response.State)
            {
               
                return Response.Dto.ToString();
            }
            else
            {

                return "";
            }
        }
    }
}
